import json
from typing import Dict

from settings import COMMON_DIR


class Building:
    def __init__(self, name, **kwargs):
        self.desc = kwargs['desc']
        self.tick = kwargs['tick']
        self.materials = kwargs['materials']

        self.prerequisites = kwargs.get('prerequisites')
        self.next = kwargs.get('next')
        self.occupy_slot = kwargs.get('occupy_slot', 1)  # 占用区划数


BUILDING_MAP: Dict[str, Building] = dict()


def loading_building():
    print("加载建筑资源...")
    with open(COMMON_DIR.joinpath('buildings.json'), 'r', encoding='utf-8') as f:
        data = json.load(f)
        for name, building in data.items():
            BUILDING_MAP[name] = Building(name, **building)
